#ifndef TASTER_H
#define TASTER_H

#include <stdint.h>
#include <avr/io.h>
#include <avr/interrupt.h>
 
#ifndef F_CPU
#define F_CPU           8000000                   // processor clock frequency
//#warning kein F_CPU definiert
#endif
 
#define KEY_DDR         DDRC
#define KEY_PORT        PORTC
#define KEY_PIN         PINC
#define KEYVOL            5
#define KEYSOUR           6

#define ALL_KEYS        (1<<KEYVOL | 1<<KEYSOUR)
 
#define REPEAT_MASK     (1<<KEYVOL | 1<<KEYSOUR)       // repeat: key1, key2
#define REPEAT_START    50                        // after 500ms 50
#define REPEAT_NEXT     20                        // every 200ms

#define PHASE_A_VOL	(PINC & (1<<PINC2))	// PINC.2
#define PHASE_B_VOL     (PINC & (1<<PINC3))	// PINC.3
 
#define PHASE_A_SOU	(PINA & (1<<PINA2))	// PINC.2
#define PHASE_B_SOU     (PINA & (1<<PINA3))	// PINC.3 
 
volatile uint8_t key_state;                                // debounced and inverted key state:
                                                  // bit = 1: key pressed
volatile uint8_t key_press;                                // key press detect
 
volatile uint8_t key_rpt;                                  // key long press and repeat



uint8_t get_key_press( uint8_t key_mask );
uint8_t get_key_rpt( uint8_t key_mask );
uint8_t get_key_state( uint8_t key_mask );
uint8_t get_key_short( uint8_t key_mask );
uint8_t get_key_long( uint8_t key_mask );
 
void encode_init( void );
int8_t encode_read_volume( void );
int8_t encode_read_source( void );

uint8_t encoder_ISR (void);



#endif //TASTER_H
